<?php

namespace Wechat\Controller;

class EvaluateController extends CommonController
{

    public function index()
    {

        $id = $_REQUEST["id"];
        $customerId = $this->customer["customer_id"];
        $map["customer_id"] = $customerId;
//        $map["day"] = date("Y-m-d");
        $info = D("Evaluate")->queryByMap($map);
        if($info["status"] == -1) {
            $this->assign("info", $info);
        }
        $this->assign("customerId", $customerId);

        $this->display("index");
    }

    public function evaluate() {

        $evaluate["create_time"] = getCurrentDate();
        $evaluate["customer_id"] = $this->customer["customer_id"];
//        $evaluate["status"] = C("BOOKING_STATUS.WAITING_PAY");
        $evaluate["name"] = I("post.name");
        $evaluate["sex"] = I("post.sex");
        $evaluate["age"] = I("post.age");
        $evaluate["mobile"] = I("post.mobile");
//        $evaluate["idcard_number"] = I("post.idcardNumber");
        $evaluate["address"] = I("post.address");
        $evaluate["disease"] = I("post.disease");
        $evaluate["note"] = I("post.note");
        $evaluate["status"] = -1;
        D("Evaluate")->add($evaluate);

        $data["code"] = 200;

        //推送信息
        $employeeList = D("Employee")->alias("e")
            ->join("left join __CUSTOMER__ c on c.customer_id = e.employee_id")
            ->field("e.*, c.openid")
            ->select();
        $openidArray = array();
        foreach ($employeeList as $singleEmployee) {
            $job = explode(',',$singleEmployee["job"]);
            if ($job[0] == "4" || $job[0] == "100") {//临床管理
                array_push($openidArray, $singleEmployee["openid"]);
            }
        }
        foreach ($openidArray as $openid) {
            $notifyData["openid"] = $openid;
            //$notifyData["url"] = "http://xwkang.com/wechat/evaluateOrder";
            $notifyData["first"] = "收到免费评估请求。";
            $notifyData["keyword1"] = "姓名：" . $evaluate["name"] . ",性别：".$evaluate["sex"]."，年龄：".$evaluate["age"]."岁";
            $notifyData["keyword2"] = $evaluate["create_time"];
            $notifyData["keyword3"] = $evaluate["disease"];
            if(isNullOrEmpty($evaluate["note"])){
                $notifyData["remark"] = "电话：".$evaluate["mobile"]."，地址：".$evaluate["disease"];
            }else{
                $notifyData["remark"] = "电话：".$evaluate["mobile"]."，地址：".$evaluate["disease"].",备注：".$evaluate["note"];
            }
            evaluateNotify($notifyData);
        }
        echo json_encode($data);

    }
}